package com.zhht.htzx.ui;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.kunminx.architecture.ui.page.DataBindingConfig;
import com.kunminx.binding_recyclerview.adapter.SimpleDataBindingAdapter;
import com.kunminx.strictdatabinding.BR;
import com.nsgf.library.data.bean.BusinessBean;
import com.nsgf.library.data.response.ResponseStatus;
import com.nsgf.library.domain.request.AccountRequester;
import com.nsgf.library.ui.page.BaseActivity;
import com.nsgf.library.ui.page.StateHolder;
import com.zhht.htzx.R;
import com.zhht.htzx.databinding.ItemBusinessSettleRecordBinding;

import java.util.List;

public class BusinessSettleRecordActivity extends BaseActivity {


    private StateHolder mStates;
    private AccountRequester mAccountRequester;

    private SimpleDataBindingAdapter<BusinessBean, ItemBusinessSettleRecordBinding> mAdapter;

    @Override
    protected void initViewModel() {
        mStates = getActivityScopeViewModel(StateHolder.class);
        mAccountRequester = getActivityScopeViewModel(AccountRequester.class);
    }

    @Override
    protected DataBindingConfig getDataBindingConfig() {
        mAdapter = new SimpleDataBindingAdapter<BusinessBean, ItemBusinessSettleRecordBinding>(this,
                R.layout.item_business_settle_record, new DiffUtil.ItemCallback<BusinessBean>() {
            @Override
            public boolean areItemsTheSame(@NonNull BusinessBean oldItem, @NonNull BusinessBean newItem) {
                return false;
            }

            @Override
            public boolean areContentsTheSame(@NonNull BusinessBean oldItem, @NonNull BusinessBean newItem) {
                return false;
            }
        }) {
            @Override
            protected void onBindItem(ItemBusinessSettleRecordBinding binding, BusinessBean item, RecyclerView.ViewHolder holder) {
                binding.setVm(item);
            }
        };
        return new DataBindingConfig(R.layout.activity_business_settle_record, BR.vm, mStates)
                .addBindingParam(BR.adapter, mAdapter);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getLifecycle().addObserver(mAccountRequester);
        mStates.titleBar.set("申请记录");
        mAccountRequester.getBusinessSettleRecord();

        mAccountRequester.getBusinessResult().observe(this, new Observer<ResponseStatus<List<BusinessBean>>>() {
            @Override
            public void onChanged(ResponseStatus<List<BusinessBean>> listResponseStatus) {

                if (listResponseStatus.getResponseCode() == 0) {
                    mStates.business.set(listResponseStatus.getData());
                }

            }
        });


    }


}
